package com.clkj.zhonghui.dao.product;

import com.clkj.zhonghui.pojo.product.ProductComment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;

/**
 * @Author：周佳润
 * @Date：2024/7/15 上午10:52
 */
@Repository
public interface ProductCommentMapper extends Mapper<ProductComment>, MySqlMapper<ProductComment> {
    @Select("<script>" +
            "select  " +
            "<if test='flag==0'> top 2 </if>" +
            "a.*,b.user_name,b.user_img  from t_zh_productComment a " +
            "left join t_zh_user b on a.user_id = b.user_id " +
            "where a.product_id = #{productId} and a.comment_status = 1 " +
            "order by topping desc " +
            "</script>")
    List<ProductComment> listComment(Integer productId,Integer flag);


    @Select("SELECT pc.*, u.user_name AS userName, u.user_img AS userImg " +
            "FROM t_zh_productComment AS pc " +
            "JOIN t_zh_user AS u ON pc.user_id = u.user_id " +
            "WHERE pc.product_id = #{productId} AND pc.comment_status = 1" +
            "ORDER BY pc.topping DESC, pc.comment_id DESC")
    List<ProductComment> selectAppComment(Integer productId);
}
